package com.example.demo3.Controller;


import com.example.demo3.Entity.StudentInfo;
import com.example.demo3.Service.StudentInfoService;
import com.example.demo3.Vo.StudentInfoClassInfo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("stu")
public class StudentInfoController {
    @Autowired
    private StudentInfoService studentInfoService;
//get请求（查询，修改，删除） record请求（添加）
    //进入，调queryStudentInfoByName方法，返回studentInfoService对象的getAllStudentInfo方法，传参数
    //http://localhost:8080/stu/query
    @GetMapping("/query")
    public List<StudentInfo> queryStudentInfoByName(@RequestParam String name) {
        return studentInfoService.getAllStudentInfo(name);
    }
    //http://localhost:8080/stu/querystu
    @GetMapping("querystu")
    public List<StudentInfoClassInfo>queryStudentInfoAndClassInfoByName(@RequestParam String name) {
        List<StudentInfoClassInfo>stuClass= studentInfoService.getAllStudentAndClassByName(name);
        return stuClass;
    }

    //http://localhost:8080/stu/del/10
    @GetMapping("del/{id}")
    private Integer delStudentInfo(@PathVariable Integer id) {
        return studentInfoService.deleteByID(id);
    }

    //http://localhost:8080/stu/add
    @PostMapping("add")
    public Integer addStudentInfo(@RequestBody StudentInfo studentInfo) {
        Integer i = studentInfoService.insertStudentInfo(studentInfo);
        return i;
    }

    //http://localhost:8080/stu/update
    @PostMapping("update")
    public Integer updateStudentInfo(@RequestBody StudentInfo studentInfo) {
        Integer i = studentInfoService.updateStudentInfo(studentInfo);
        return i;
    }

    @GetMapping("page")
    public PageInfo<StudentInfoClassInfo> pageStudentInfoClassInfo(@RequestParam Integer page,@RequestParam Integer size) {
        return studentInfoService.getPageStudentInfoClassInfo(page,size);
    }
}
